import axios from 'axios'
import MockAdapter from 'axios-mock-adapter';
import userListS from '../../staticData/userList';

// mock.onGet(/\/^api/).passThrough()
const userList = userListS
function loginMock() {
    let mock = new MockAdapter(axios)
    mock.onPost('/api/login').reply(config => {
        const { username, password } = JSON.parse(config.data);
        const user = userList.get(username)?.password;

        if (user && user === password) {
            return [200,'success'];
        } else {
            return [401, { error: 'Invalid credentials' }];
        }
    });
}

export default loginMock